package com.zheng.damo01.liko;

import java.math.BigDecimal;
import java.util.Arrays;

public class Solution01 {
    public static void main(String[] args) {
        int[] arr1={1,2,3,4};
        int[] arr2={5,6,7,8};

        System.out.println(new Solution01().findMedianSortedArrays(arr1,arr2));
    }
    public double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int size=nums1.length+nums2.length;
        int[] arr=new int[size];
        for (int i = 0; i < arr.length; i++) {
            if (i>=nums1.length){
                arr[i]=nums2[i-nums1.length];
            }else {
                arr[i]=nums1[i];
            }
        }
        Arrays.sort(arr);
        System.out.println(Arrays.toString(arr));
        if (arr.length%2==1){
            return (double) arr[arr.length/2];
        }else {
            return BigDecimal.valueOf(arr[arr.length/2-1]).add(BigDecimal.valueOf(arr[arr.length/2])).divide(BigDecimal.valueOf(2)).doubleValue();
        }
        //System.out.println(Arrays.toString(arr));

    }
}
